var path = require("path"),
    glob = require('glob'),
    webpack = require('webpack'),
    appDir = __dirname + "/app",
    getEntry = function() {
        var entry = {};
        glob.sync(appDir + '/views/*.ts').forEach(function(name) {
            var n = name.slice(name.lastIndexOf('views/') + 6, name.length - 3).replace('views', '');
            entry[n] = name;
        });
        return entry;
    };
var entries = getEntry();


var config = {
    context: appDir,
    entry: entries,
    watch: false,
    output: {
        path: path.join(__dirname, "dist"),
        filename: "[name].min.js",
        chunkFilename: "[id].chunk.js"
    },
    resolve: {
        extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },
    module: {
        loaders: [ //加载器
            {
                test: /\.tpl|.hbs$/,
                loader: "html"
            },
            //{ test: /\.hbs&/, loader: 'handlebars-loader' },
            { test: /\.ts?$/, loader: "ts-loader" }
        ]
    },
    externals: {
        jquery: 'jQuery',
        underscore: '_',
        knockout: 'ko',
        template: 'template',
        mustache: 'Mustache',
        moment: 'moment',
        handlebars: 'Handlebars'
    }
};


module.exports = config;